
<%@page import="java.util.List"%>
<%@page import="com.garagesale.data.User"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<!-- The following page directive is needed for c:out to work properly.. otherwise,  -->
<!-- you get the following error: "According to TLD or attribute directive in tag file, attribute var does not accept any..." -->


<%@include file="/WEB-INF/jspf/tagImports.jspf" %>

<html:html lang="true">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>
      <tags:header message="WELCOME" />
    </title>
    <html:base/>
  </head>
  <div id = "top"><a href="">View Items(1)</a> |
    <c:url var="welcomeUrl" value="/welcome.do">
      <c:param name="removeUserFromSession" value="true" />
    </c:url>
    <a href="${welcomeUrl}">Remove Current User From Session </a>
  </div>

  <div id = "header">
    <img alt="" src="images/banner1.gif" style="width: 780px; height: 162px" />
  </div>
  <div id = "menu">
    <c:url var="createItemUrl" value="/jsp/admin/index.jsp" />
    <a href="${createItemUrl}"> Administrator </a><br></br>

    <c:choose>
        <c:when test="${sessionScope.user ne null}">
            <span>
                Logged in as <c:out value="${sessionScope.user.username}" />
                &nbsp;
                &nbsp;
                <c:url var="logoutUrl" value="/user/logout.do" />
                <a href="${logoutUrl}">Logout</a>
            </span>
        </c:when>
        <c:otherwise>
            <c:url var="loginUrl" value="/user/login.do" />
            <a href="${loginUrl}">Login</a>
        </c:otherwise>
    </c:choose>
  </div>
  <div id="content">
    <tags:body>
    <logic:notPresent name="org.apache.struts.action.MESSAGE" scope="application">
      <div  style="color: red">
        ERROR:  Application resources not loaded -- check servlet container
        logs for error messages.
      </div>
    </logic:notPresent>

    <c:if test="${not empty requestScope.removedUser}">
      <br />
      <c:out value="Removed ${requestScope.removedUser.firstName} from the session" />
      <br />
    </c:if>

    <c:url var="createUserUrl" value="/user/viewUser.do?action=create" />
    <a href="${createUserUrl}">Create User</a>
    <br />

    <h3>Users:</h3>
    <table style="border-style: solid;">
      <tr style="border-style: inherit;">
        <th>First Name</th>
        <th>Last Name</th>
        <th>Username</th>
        <th>Email Address</th>
        <th>View User (Puts the user in the session)</th>
      </tr>
      <c:forEach var="user" items="${users}" >
        <tr>
          <td><c:out value="${user.firstName}" /></td>
          <td><c:out value="${user.lastName}" /></td>
          <td><c:out value="${user.username}" /></td>
          <td><c:out value="${user.emailAddress}" /></td>
          <td>
            <c:url var="viewUserUrl" value="/user/viewUser.do">
              <c:param name="userID" value="${user.userID}" />
            </c:url>
            <a href="${viewUserUrl}">
              View <b><c:out value="${user.username}" /></b>
            </a>
          </td>
        </tr>
      </c:forEach>
    </table>


    <h3>Categories:</h3>
    <table style="border-style: solid;">
      <tr style="border-style: inherit;">
        <th>Name</th>
        <th>Color</th>
      </tr>
      <c:forEach var="category" items="${categories}" >
        <tr>
          <td><c:out value="${category.name}" /></td>
          <td style="background-color: ${category.labelColor};"><c:out value="${category.labelColor}" /></td>
        </tr>
      </c:forEach>
    </table>

    <h3>Administrators:</h3>
    <table style="border-style: solid;">
      <tr style="border-style: inherit;">
        <th>UserName</th>
        <th>Password</th>
        <th>Email</th>
      </tr>
      <c:forEach var="administrator" items="${admin}" >
        <tr>
          <td><c:out value="${administrator.username}" /></td>
          <td><c:out value="${administrator.password}" /></td>
          <td><c:out value="${administrator.emailAddress}" /></td>
        </tr>
      </c:forEach>
    </table>

    <br />
    <c:url var="listItemsUrl" value="/user/listItems.do" />
    <a href="${listItemsUrl}">List Items</a>
    <br />

    <h3>Items found by first category in list:</h3>
    <table style="border-style: solid;">
      <tr style="border-style: inherit;">
        <th>Name</th>
        <th>Description</th>
        <th>Price</th>
        <th>View</th>
      </tr>
      <c:forEach var="item" items="${foundItems}" >
        <tr>
          <c:url var="viewItemUrl" value="/user/viewItem.do">
            <c:param name="itemID" value="${item.itemID}" />
          </c:url>
          <td><c:out value="${item.name}" /></td>
          <td><c:out value="${item.description}" /></td>
          <td><c:out value="${item.salePrice}" /></td>
          <td><a href="${viewItemUrl}">View Item </a> </td>
        </tr>

      </c:forEach>
    </table>

    <h3>Add Item Category</h3> <a href="${createItemUrl}">Click Here</a>


    <h3>All Items in the system:</h3>
    <table style="border-style: solid;">
      <tr style="border-style: inherit;">
        <th>Name</th>
        <th>Description</th>
        <th>Price</th>
        <th>View</th>
      </tr>
      <c:forEach var="item" items="${allItems}" >
        <tr>
          <c:url var="viewItemUrl" value="/user/viewItem.do">
            <c:param name="itemID" value="${item.itemID}" />
          </c:url>
          <td><c:out value="${item.name}" /></td>
          <td><c:out value="${item.description}" /></td>
          <td><c:out value="${item.salePrice}" /></td>
          <td><a href="${viewItemUrl}">View Item </a> </td>
        </tr>
      </c:forEach>
    </table>
   
    </tags:body>
  </div>
  <div id = "footer">
    <span>
    &nbsp;All rights reserved Garage Sale 2011 | Legal | Privacy Policy
    </span>
    <br><br>
    <img alt="" src="images/b1.gif">
    <img alt="" src="images/b2.gif" style="margin:0px 5px 0px 5px">
    <img alt="" src="images/b3.gif">
  </div>
</html:html>
